﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using SysCommon.Tools;

namespace TMSIM.Client.CM.UI.MainFrm
{
    public partial class QueryCtrl : UserControl
    {
      
        private static List<string> m_carplates = new List<string>();

       
        public static string[] GetSelfDefinedCars()
        {
            return m_carplates.ToArray();            
        }

        public QueryCtrl()
        {
            InitializeComponent();
            
        }
        
        public void init()
        {
           
        }

       

        private void btn_Query_Click(object sender, EventArgs e)
        {
            try
            {
               
               
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用自定义监控的查找函数失败", ex);
                SysCommon.MsgBox.SysMessageBox.ShowInfoMessageBox(null, "查找失败", false);
            }
        }

        private void btn_AddSC_Click(object sender, EventArgs e)
        {
            try
            {
                DataGridViewRow rows = dg_DataView.CurrentRow;
                if (rows == null) return;
                string mCARPLATE = rows.Cells["CARPLATE"].Value.ToString().Trim();
                if (mCARPLATE.Trim() == "") return;

                SetRealTimeStaute("自定义监控", mCARPLATE);
            }
            catch
            {
                SysCommon.MsgBox.SysMessageBox.ShowInfoMessageBox(null, "未选中车辆", false);
            }
        }

        public void SetRealTimeStaute(string selText, string carplate)
        {
            try
            {
                if (!m_carplates.Contains(carplate))
                {
                    m_carplates.Add(carplate);
                }
                TMSIM.Client.CM.Entity.RefreshRealTimeCtrlEventArgs e = new TMSIM.Client.CM.Entity.RefreshRealTimeCtrlEventArgs();
                AppCommon.ManageEvent.EventManager em = AppCommon.ManageEvent.EventManager.GetInstance();

                e.RoadName = "";
                e.AreadCode = "";
                e.IsDanger = false;
                e.IsZoom = true;
                e.Carmember = "";
                e.Carplate = m_carplates.ToArray();

                string strTitle = selText;
                if (strTitle.Length == 0) strTitle = "广东省车队";
                e.Title = strTitle;

                em.FireEvent(e);
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("添加自定义监控车辆出错", ex);
            }
            //CMGlobal.mainfrm.realTimeCtrl1.QueryPeccancy("", "", "", carplate);
            //CMGlobal.mainfrm.realTimeCtrl1.QueryAlarmHistory("", "", "", carplate);
            //CMGlobal.mainfrm.realTimeCtrl1.QueryWarn("", "", "", carplate);
            //CMGlobal.mainfrm.realTimeCtrl1.QueryCurrStakeoutCar("", "", "", carplate);
        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            //string m_selText = "自定义监控";
            //string areacode = CMGlobal.mainfrm.monitorCtrl1.CurrentUserAreacode;

            //CMGlobal.mainfrm.realTimeCtrl1.tp_TransgressInfo.Text = m_selText + "违章信息";
            //CMGlobal.mainfrm.realTimeCtrl1.tp_CallPoliceInfo.Text = m_selText + "报警信息";
            ////CMGlobal.mainfrm.realTimeCtrl1.tp_WarnInfo.Text = m_selText + "警告信息";
            //CMGlobal.mainfrm.realTimeCtrl1.tp_CurrStakeoutCarInfo.Text = m_selText + "在线车辆全部信息";

            try
            {
                TMSIM.Client.CM.Entity.RefreshRealTimeCtrlEventArgs e1 = new TMSIM.Client.CM.Entity.RefreshRealTimeCtrlEventArgs();
                AppCommon.ManageEvent.EventManager em = AppCommon.ManageEvent.EventManager.GetInstance();

                e1.RoadName = "";
                e1.AreadCode = "";
                e1.IsDanger = false;
                e1.IsZoom = true;
                e1.Carmember = "";
                //e1.Carplate = new string[] { "NULL" };
                dg_DataView.MultiSelect = true;
                if (dg_DataView.SelectedRows == null)
                {
                    MessageBox.Show("请选择所要删除车辆的行!", "信息提示");
                    return;

                }
                foreach (DataGridViewRow r in dg_DataView.SelectedRows)
                {
                    string carplate = r.Cells["CARPLATE"].Value.ToString();
                    if(m_carplates.Contains(carplate))
                    {
                       m_carplates.Remove(carplate);
                    }



                }
                e1.Carplate = m_carplates.ToArray();
                MessageBox.Show("删除所选车辆成功!", "信息提示");
              
                string strTitle = "自定义监控";
                if (strTitle.Length == 0) strTitle = "广东省车队";
                e1.Title = strTitle;

                em.FireEvent(e1);
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("清空自定义监控车辆出错", ex);
            }
            //CMGlobal.mainfrm.realTimeCtrl1.QueryPeccancy(areacode, "", m_selText, "");
            //CMGlobal.mainfrm.realTimeCtrl1.QueryAlarmHistory(areacode, "", m_selText, "");
            //CMGlobal.mainfrm.realTimeCtrl1.QueryWarn(areacode, "", m_selText, "");
            //CMGlobal.mainfrm.realTimeCtrl1.QueryCurrStakeoutCar(areacode, "", m_selText, "");
        }

        private void cmb_Type_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                txt_KeyWord.Text = "";
                dg_DataView.DataSource = null;
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("清除自定义不同监控类型出错",ex);
            }
        }
    }
}
